/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package roomarrange;

import com.sun.data.provider.impl.CachedRowSetDataProvider;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.TextField;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.faces.convert.IntegerConverter;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version videorecord2.java
 * @version Created on 2009-11-18, 15:21:03
 * @author ben
 */
public class videorecord2 extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
        t_usrsetDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.t_usrsetRowSet}"));
        v_usrDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.v_usrListA}"));
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }
    private CachedRowSetDataProvider t_usrsetDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getT_usrsetDataProvider() {
        return t_usrsetDataProvider;
    }

    public void setT_usrsetDataProvider(CachedRowSetDataProvider crsdp) {
        this.t_usrsetDataProvider = crsdp;
    }
    private IntegerConverter dropDown1Converter = new IntegerConverter();

    public IntegerConverter getDropDown1Converter() {
        return dropDown1Converter;
    }

    public void setDropDown1Converter(IntegerConverter ic) {
        this.dropDown1Converter = ic;
    }
    private TextField docno = new TextField();

    public TextField getDocno() {
        return docno;
    }

    public void setDocno(TextField tf) {
        this.docno = tf;
    }
    private TextField cname = new TextField();

    public TextField getCname() {
        return cname;
    }

    public void setCname(TextField tf) {
        this.cname = tf;
    }
    private TextField caseno = new TextField();

    public TextField getCaseno() {
        return caseno;
    }

    public void setCaseno(TextField tf) {
        this.caseno = tf;
    }
    private TextField suspect = new TextField();

    public TextField getSuspect() {
        return suspect;
    }

    public void setSuspect(TextField tf) {
        this.suspect = tf;
    }
    private TextField casecause = new TextField();

    public TextField getCasecause() {
        return casecause;
    }

    public void setCasecause(TextField tf) {
        this.casecause = tf;
    }
    private TextField notice = new TextField();

    public TextField getNotice() {
        return notice;
    }

    public void setNotice(TextField tf) {
        this.notice = tf;
    }
    private TextField crefmtid = new TextField();

    public TextField getCrefmtid() {
        return crefmtid;
    }

    public void setCrefmtid(TextField tf) {
        this.crefmtid = tf;
    }
    private TextField cabstract = new TextField();

    public TextField getCabstract() {
        return cabstract;
    }

    public void setCabstract(TextField tf) {
        this.cabstract = tf;
    }
    private CachedRowSetDataProvider v_usrDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getV_usrDataProvider() {
        return v_usrDataProvider;
    }

    public void setV_usrDataProvider(CachedRowSetDataProvider crsdp) {
        this.v_usrDataProvider = crsdp;
    }
    private DropDown acceptor = new DropDown();

    public DropDown getAcceptor() {
        return acceptor;
    }

    public void setAcceptor(DropDown dd) {
        this.acceptor = dd;
    }

    // </editor-fold>
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public videorecord2() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here

        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("videorecord2 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
        }

    // </editor-fold>
    // Perform application initialization that must complete
    // *after* managed components are initialized
    // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
        try {
            CachedRowSet crs = this.getSessionBean1().getV_usrListA();
            crs.setObject(1, 27);
            crs.execute();
        } catch (SQLException ex) {
            Logger.getLogger(admin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //this.getDropDown1().setSelected(this.getSessionBean1().getIusrid());
            this.getDocno().setText(this.getSessionBean1().getMts().getCdocno());
            this.getCname().setText(this.getSessionBean1().getMts().getSCname());
            this.getCaseno().setText(this.getSessionBean1().getMts().getCcaseno());
            this.getCasecause().setText(this.getSessionBean1().getMts().getCcasecause());
            this.getCabstract().setText(this.getSessionBean1().getMts().getSCabstract());
            this.getNotice().setText(this.getSessionBean1().getMts().getSCnotice());
            this.getCrefmtid().setText(this.getSessionBean1().getMts().getCrefmtid());
            this.getSuspect().setText(this.getSessionBean1().getMts().getCsuspect());
            this.getAcceptor().setSelected(this.getSessionBean1().getMts().getCacceptor());

    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
        t_usrsetDataProvider.close();
        v_usrDataProvider.close();
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    public String button2_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        this.getDocno().setText("");
        this.getCname().setText("");
        this.getCaseno().setText("");
        this.getSuspect().setText("");
        this.getCasecause().setText("");
        this.getCabstract().setText("");
        this.getNotice().setText("");
        this.getCrefmtid().setText("");
        return null;
    }

    public String button1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        //提交并确认
        int li_bj = 0;
        int li_status = 0;
        int li_roomid = 0;
        int li_roomsort = 0;
        int li_host = 0;
        int li_initdept = 0;
        String sTip = null;
        String sRef = null;
        works lwks = new works();
        String sMeetingid = this.getSessionBean1().getSUUID();
        //将host设置为自己
        li_host = this.getSessionBean1().getIusrid();
        li_initdept = this.getSessionBean1().getIMtInitdept();
        //赋值

        if (this.getCname().getText() == null) {
            lwks.setCname(" ");
        } else {
            lwks.setCname(this.getCname().getText().toString()); //办案部门
        }
        if (this.getCabstract().getText() == null) {
            lwks.setCabstract(" ");
        } else {
            lwks.setCabstract(this.getCabstract().getText().toString()); //询问地点
        }
        if (this.getNotice().getText() == null) {
            lwks.setCnotice(" ");
        } else {
            lwks.setCnotice(this.getNotice().getText().toString());//联系电话
        }
        if (this.getCrefmtid().getText() == null) {
            lwks.setCrefmtid(" ");
        } else {
            lwks.setCrefmtid(this.getCrefmtid().getText().toString()); //备注
        }
        if (this.getDocno().getText() == null) {
            lwks.setCdocno(" ");
        } else {
            lwks.setCdocno(this.getDocno().getText().toString()); //津西检录
        }
        if (this.getCaseno().getText() == null) {
            lwks.setCcaseno(" ");
        } else {
            lwks.setCcaseno(this.getCaseno().getText().toString()); //案件编号
        }
        if (this.getCasecause().getText() == null) {
            lwks.setCcasecause(" ");
        } else {
            lwks.setCcasecause(this.getCasecause().getText().toString()); //案由
        }
        if (this.getSuspect().getText() == null) {
            lwks.setCsuspect(" ");
        } else {
            lwks.setCsuspect(this.getSuspect().getText().toString()); //被询问人
        }
        if (this.getAcceptor().getSelected() == null) {
            lwks.setCacceptor(" ");
        } else {
            lwks.setCacceptor(this.getAcceptor().getSelected().toString()); //受理人
        }
        lwks.setI_id(sMeetingid); //记录编号
        lwks.setIhost(li_host);
        lwks.setCinitdept(li_initdept);

        sRef = this.getSessionBean1().getSRef();

        li_roomid = this.getSessionBean1().getIroomid();
        //更新

        //生成临时数据
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig.xml");
        DataSource ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        //DataSource ds = (DataSource) ctx.getBean("dataSourcePool");
        DataJdbcDao taskDao = new DataJdbcDao();
        taskDao.setDataSource(ds);
        //取会议室类别
        li_roomsort = taskDao.getRoomSort(li_roomid);
        switch (li_roomsort) {
            case 4:
                //工作区
                li_status = 1;
                sTip = "工作区已成功申请，正等待本部门领导审批！";
                break;
            case 5:
                //全程录像
                li_status = 1;
                sTip = "全程录像已成功申请，正等待本部门领导审批！";
                break;
            case 6:
                //侦查指挥中心
                li_status = 1;
                sTip = "侦查指挥中心已成功申请，正等待本部门领导审批！";
                break;
        }
        //更新会议数据
        lwks.setIstatus(li_status);
        taskDao.updateWork(lwks);
        //向qq发信息,如果是直接确认的申请才发消息
        if (sRef.equalsIgnoreCase("videorecord")) {
            //只有从videorecord页过来的请求才是新增加的，其他的是修改的请求
            //插入的时候发消息，要将bj设置为7
            int ibj = 7;
            meetings mt = new meetings();
            String sapp = this.getSessionBean1().getSApp();
            mt = taskDao.getMeeting(sMeetingid, sapp);
            setupParam stp = new setupParam();
            stp = taskDao.getParam();

            taskDao.sendRTX(mt, ibj,stp);
        }
        //显示提示信息
        this.getSessionBean1().setSTip(sTip);
        //cls
        this.getSessionBean1().setIMtHost(0);
        this.getSessionBean1().setIMtInitdept(0);
        this.getSessionBean1().setIroomid(0);
        this.getSessionBean1().setSEdate("");
        this.getSessionBean1().setSSdate("");
        this.getSessionBean1().setSUUID("");
        this.getSessionBean1().setSMtAbstract("");
        this.getSessionBean1().setSMtName("");
        this.getSessionBean1().setSMtNotice("");
        this.getSessionBean1().setSRefMtId("");

        return "toSucc2";
    }
}

